
import SelectAppList from '@/components/select-app-list';

export default {
    name: 'loan-data',
    components: {
        SelectAppList
    },
    data() {
        return {
            language: this.$storage.getLocal('language'),
            form: {
                date: '',
                userType: 3,
                appName: []
            },
            rules: {},
            tableData: [],
            dataTotal: {},
            tableMaxHeight: 500,
        };
    },
    watch: {
    },
    methods: {
        // 获取列表数据
        getTableData() {
            this.tableData = [];
            this.$api.report.queryAppNewuserRiskRate({ appNames: this.form.appName }).then(res => {
                const {status, data, error} = res;
                if ('1' === status && '00000000' === error && data) {
                    const list = data.appNewuserRiskRates || [];
                    this.tableData = list.map(item => {
                        if (item.date && typeof item.date === 'string')
                        item.date = item.date.split(' ')[0];
                        return item;
                    });
                    const { orderCountSum, admittanceSuccessSum, admittanceRefuseSum, admittanceSuccessRateSum, lastAuditSuccessSum, dateLoanSum, dateLoanRateSum, lastAuditSuccessRateSum } = data;
                    this.dataTotal = {
                        orderCountSum,
                        admittanceSuccessSum,
                        admittanceRefuseSum,
                        admittanceSuccessRateSum,
                        lastAuditSuccessSum,
                        dateLoanSum,
                        dateLoanRateSum,
                        lastAuditSuccessRateSum,
                    };
                }
                this.tableMaxHeight = document.body.clientHeight - 165;
            });
        },
        exportExcel() {
            let params = {
                appNames: this.form.appName,
            };
            const user = this.$storage.get("user");
            params.language = this.$storage.getLocal('language');
            params.token = user.token;
            const {$apiConf} = this;
            const url = this.$urlUtil.fillParams(params, $apiConf.baseUrl + $apiConf.urlType.report.appNewuserRiskRateExport, ["page"]);
            this.$openNewBlank(url);
        },
        toPercent(point){
            if (!point) {
                return '0%';
            }
            let str = Number(point * 100).toFixed(2);
            str += "%";
            return str;
        },
        // 总计数据
        getSummaries(param) {
            const { columns } = param;
            const sums = [];
            columns.forEach((item,index)=> {
                if (index === 0) {
                    sums[index] = this.$t('common.totals');
                    return;
                }
                switch (item.property) {
                    case 'orderCount':
                        sums[index] = this.dataTotal.orderCountSum
                        break;
                    case 'admittanceSuccess':
                        sums[index] = this.dataTotal.admittanceSuccessSum
                        break;
                    case 'admittanceRefuse':
                        sums[index] = this.dataTotal.admittanceRefuseSum
                        break;
                    case 'admittanceSuccessRate':
                        sums[index] = this.dataTotal.admittanceSuccessRateSum
                        break;
                    case 'lastAuditSuccess':
                        sums[index] = this.dataTotal.lastAuditSuccessSum
                        break;
                    case 'dateLoan':
                        sums[index] = this.dataTotal.dateLoanSum
                        break;
                    case 'dateLoanRate':
                        sums[index] = this.dataTotal.dateLoanRateSum
                        break;
                    case 'lastAuditSuccessRate':
                        sums[index] = this.dataTotal.lastAuditSuccessRateSum
                        break;
                    default:
                        break;
                }
            })
            return sums;
        }
    },
    created() {
        this.getTableData()
    },
};
